import { ArticleStatus, BatchOperationType } from "@/api/article-management";

/** 文章状态选项 */
export const ARTICLE_STATUS_OPTIONS = [
  { label: "全部", value: "" },
  { label: "草稿", value: ArticleStatus.DRAFT },
  { label: "已发布", value: ArticleStatus.PUBLISHED },
  { label: "已删除", value: ArticleStatus.DELETED },
  { label: "待审核", value: ArticleStatus.PENDING },
  { label: "审核拒绝", value: ArticleStatus.REJECTED },
  { label: "已下架", value: ArticleStatus.UNPUBLISHED }
];

/** 文章状态颜色映射 */
export const ARTICLE_STATUS_COLORS = {
  [ArticleStatus.DRAFT]: "#909399",
  [ArticleStatus.PUBLISHED]: "#67C23A",
  [ArticleStatus.DELETED]: "#F56C6C",
  [ArticleStatus.PENDING]: "#E6A23C",
  [ArticleStatus.REJECTED]: "#F56C6C",
  [ArticleStatus.UNPUBLISHED]: "#E6A23C"
};

/** 是否置顶选项 */
export const IS_TOP_OPTIONS = [
  { label: "全部", value: "" },
  { label: "置顶", value: 1 },
  { label: "非置顶", value: 0 }
];

/** 是否原创选项 */
export const IS_ORIGINAL_OPTIONS = [
  { label: "全部", value: "" },
  { label: "原创", value: 1 },
  { label: "转载", value: 0 }
];

/** 排序字段选项 */
export const SORT_FIELD_OPTIONS = [
  { label: "发布时间", value: "publish_time" },
  { label: "创建时间", value: "create_time" },
  { label: "更新时间", value: "update_time" },
  { label: "浏览量", value: "view_count" },
  { label: "点赞数", value: "like_count" },
  { label: "评论数", value: "comment_count" },
  { label: "字数", value: "word_count" }
];

/** 排序方向选项 */
export const SORT_ORDER_OPTIONS = [
  { label: "降序", value: "desc" },
  { label: "升序", value: "asc" }
];

/** 批量操作选项 */
export const BATCH_OPERATION_OPTIONS = [
  {
    label: "审核通过",
    value: BatchOperationType.APPROVE,
    icon: "ep:check",
    type: "success"
  },
  {
    label: "审核拒绝",
    value: BatchOperationType.REJECT,
    icon: "ep:close",
    type: "danger"
  },
  {
    label: "发布",
    value: BatchOperationType.PUBLISH,
    icon: "ep:promotion",
    type: "primary"
  },
  {
    label: "下架",
    value: BatchOperationType.UNPUBLISH,
    icon: "ep:download",
    type: "warning"
  },
  {
    label: "置顶",
    value: BatchOperationType.TOP,
    icon: "ep:top",
    type: "success"
  },
  {
    label: "取消置顶",
    value: BatchOperationType.UNTOP,
    icon: "ep:bottom",
    type: "info"
  },
  {
    label: "删除",
    value: BatchOperationType.DELETE,
    icon: "ep:delete",
    type: "danger"
  },
  {
    label: "恢复",
    value: BatchOperationType.RESTORE,
    icon: "ep:refresh",
    type: "success"
  }
];

/** 审核结果选项 */
export const AUDIT_RESULT_OPTIONS = [
  { label: "审核通过", value: 1, type: "success" },
  { label: "审核拒绝", value: 4, type: "danger" }
];

/** 表格列配置 */
export const ARTICLE_TABLE_COLUMNS = [
  { prop: "id", label: "ID", width: 80, sortable: true },
  { prop: "title", label: "标题", minWidth: 200, showOverflowTooltip: true },
  { prop: "authorNickName", label: "作者", width: 120 },
  { prop: "categoryName", label: "分类", width: 120 },
  { prop: "status", label: "状态", width: 100 },
  { prop: "isTop", label: "置顶", width: 80 },
  { prop: "isOriginal", label: "原创", width: 80 },
  { prop: "viewCount", label: "浏览量", width: 100, sortable: true },
  { prop: "likeCount", label: "点赞数", width: 100, sortable: true },
  { prop: "commentCount", label: "评论数", width: 100, sortable: true },
  { prop: "wordCount", label: "字数", width: 100, sortable: true },
  { prop: "publishTime", label: "发布时间", width: 180, sortable: true },
  { prop: "actions", label: "操作", width: 200, fixed: "right" }
];

/** 分页配置 */
export const PAGINATION_CONFIG = {
  /** 默认页码 */
  defaultCurrent: 1,
  /** 默认每页大小 */
  defaultSize: 10,
  /** 每页大小选项 */
  pageSizes: [10, 20, 50, 100],
  /** 布局 */
  layout: "total, sizes, prev, pager, next, jumper"
};

/** 搜索表单配置 */
export const SEARCH_FORM_CONFIG = {
  /** 标签宽度 */
  labelWidth: "80px",
  /** 表单项间距 */
  gutter: 20,
  /** 每行显示的表单项数量 */
  span: 6
};

/** Markdown预览配置 */
export const MARKDOWN_PREVIEW_CONFIG = {
  /** 默认主题 */
  defaultTheme: "default",
  /** 主题选项 */
  themeOptions: [
    { label: "默认", value: "default" },
    { label: "GitHub", value: "github" },
    { label: "暗色", value: "dark" }
  ],
  /** 默认启用的功能 */
  defaultFeatures: {
    enableCodeHighlight: true,
    enableMath: false,
    enableTable: true,
    enableTaskList: true,
    enableStrikethrough: true,
    enableAutolink: true
  }
};

/** 消息文本 */
export const MESSAGES = {
  /** 成功消息 */
  SUCCESS: {
    AUDIT_APPROVE: "文章审核通过",
    AUDIT_REJECT: "文章审核拒绝",
    BATCH_OPERATION: "批量操作成功",
    PUBLISH: "文章发布成功",
    UNPUBLISH: "文章下架成功",
    TOP: "文章置顶成功",
    UNTOP: "取消置顶成功",
    DELETE: "文章删除成功",
    RESTORE: "文章恢复成功"
  },
  /** 确认消息 */
  CONFIRM: {
    AUDIT_APPROVE: "确认审核通过这篇文章吗？",
    AUDIT_REJECT: "确认拒绝这篇文章吗？",
    BATCH_OPERATION: "确认执行批量操作吗？",
    PUBLISH: "确认发布这篇文章吗？",
    UNPUBLISH: "确认下架这篇文章吗？",
    TOP: "确认置顶这篇文章吗？",
    UNTOP: "确认取消置顶吗？",
    DELETE: "确认删除这篇文章吗？删除后可以恢复。",
    RESTORE: "确认恢复这篇文章吗？"
  },
  /** 错误消息 */
  ERROR: {
    LOAD_FAILED: "加载数据失败",
    OPERATION_FAILED: "操作失败",
    NETWORK_ERROR: "网络错误，请稍后重试",
    PERMISSION_DENIED: "权限不足",
    ARTICLE_NOT_FOUND: "文章不存在",
    INVALID_PARAMS: "参数错误"
  },
  /** 验证消息 */
  VALIDATION: {
    TITLE_REQUIRED: "请输入文章标题",
    TITLE_TOO_LONG: "文章标题不能超过100个字符",
    SUMMARY_REQUIRED: "请输入文章摘要",
    SUMMARY_TOO_LONG: "文章摘要不能超过500个字符",
    CATEGORY_REQUIRED: "请选择文章分类",
    CONTENT_REQUIRED: "请输入文章内容",
    AUDIT_REMARK_REQUIRED: "请输入审核备注",
    SELECT_ARTICLES: "请选择要操作的文章",
    SELECT_OPERATION: "请选择操作类型"
  }
};

/** 默认查询参数 */
export const DEFAULT_QUERY_PARAMS = {
  current: 1,
  size: 10,
  sortField: "publish_time",
  sortOrder: "desc" as const
};

/** 文章管理权限 */
export const ARTICLE_PERMISSIONS = {
  /** 查看文章列表 */
  VIEW_LIST: "article:list",
  /** 查看文章详情 */
  VIEW_DETAIL: "article:detail",
  /** 审核文章 */
  AUDIT: "article:audit",
  /** 发布文章 */
  PUBLISH: "article:publish",
  /** 下架文章 */
  UNPUBLISH: "article:unpublish",
  /** 置顶文章 */
  TOP: "article:top",
  /** 删除文章 */
  DELETE: "article:delete",
  /** 恢复文章 */
  RESTORE: "article:restore",
  /** 批量操作 */
  BATCH_OPERATION: "article:batch"
};

/** 编辑器类型枚举 */
export enum EditorType {
  MARKDOWN = 1, // Markdown编辑器
  RICH_TEXT = 2 // 富文本编辑器
}

/** 编辑器类型枚举常量（兼容旧的使用方式） */
export const EDITOR_TYPES = {
  MARKDOWN: EditorType.MARKDOWN,
  RICH_TEXT: EditorType.RICH_TEXT
} as const;

/** 编辑器类型标签 */
export const EDITOR_TYPE_LABELS = {
  [EditorType.MARKDOWN]: "Markdown编辑器",
  [EditorType.RICH_TEXT]: "富文本编辑器"
} as const;

/** 编辑器类型选项（用于下拉选择） */
export const EDITOR_TYPE_OPTIONS = [
  {
    label: EDITOR_TYPE_LABELS[EditorType.MARKDOWN],
    value: EditorType.MARKDOWN,
    icon: "ri:markdown-line",
    description: "使用Markdown语法编写内容，支持代码高亮、数学公式等"
  },
  {
    label: EDITOR_TYPE_LABELS[EditorType.RICH_TEXT],
    value: EditorType.RICH_TEXT,
    icon: "ri:edit-2-line",
    description: "所见即所得的富文本编辑器，支持格式化文本、表格、图片等"
  }
] as const;
